<template>
	<view class="container">
		<view class="header-swiper">
			<swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" circular="true"
				indicator-color="#FFF5D5" indicator-active-color="#FCC309" :interval="interval" :duration="duration">
				<swiper-item v-for="(item, index) in swoingList" :key="index" @click="clickHeaderImg(item)">
					<image class="banner-img" :src="item.imgUrl"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="type-container" style="padding:0rpx 0rpx 10rpx">
			<view v-for="(item, index) in typeList" :key="index" @click="gotoPage(item)" v-if="item.show"
				class="type-container__item">
				<view class="baner-top-item">
					<view class="type-container__item-icon-box">
						<image :src="item.icon" class="type-container__item-icon"></image>
					</view>

					<text>{{ item.text }}</text>
				</view>
			</view>
		</view>
		<view class="hot-container" v-if="showjl&&playerList.length > 0">
			<view class="hot-container__header">
				<view class="hot-container__header-name">人气榜</view>
			</view>
			<view class="hot-swiper"><home-hot class="hot-swiper__item" v-for="(item, index) in playerList" :key="index"
					:itemData="item"></home-hot></view>
		</view>
		<view class="hot-container" v-if="showjl&&onlinePlayList.length > 0">
			<view class="hot-container__header">
				<view class="hot-container__header-name">推荐榜</view>
			</view>
			<view class="hot-swiper" style="height:406rpx;">
				<home-online-hot class="hot-swiper__item" v-for="(item, index) in onlinePlayList" :key="index"
					:itemData="item"></home-online-hot>
			</view>
		</view>
		<view class="hot-container" v-if="showjl&&productList.length > 0">
			<view class="hot-container__header">
				<view class="hot-container__header-name">热卖榜</view>
			</view>
			<view class="hot-swiper"><home-sell class="hot-swiper__item" v-for="(item, index) in productList"
					:key="index" :itemData="item"></home-sell></view>
		</view>


	</view>
</template>

<script>
	import vip_icon from '../../static/images/vip.png';
	import shangcheng_icon from '../../static/images/mall.png';
	import daren_icon from '../../static/images/topman.png';
	import room_icon from '../../static/images/guest_room.png';
	import recharge_icon from '../../static/images/rechargeindex.png';
	import online_daren_icon from '../../static/images/online_daren_icon.png';
	import homeHot from '../../components/home-hot.vue';
	import homeOnlineHot from '../../components/home-online-hot.vue';
	import homeSell from '../../components/home-sell.vue';
	import {
		getDefaultInfo,
		queryPlayerList,
		listMallProduct,
		allHomePage
	} from '@/constant/home.js';
	import {
		isLogin,
		toLogin,
		showShareMenu
	} from '@/config/common.js';
	import {
		checkPermission,
		checkWetchatEnableYueWan
	} from '@/config/utils.js';
	import {
		getAppServePlayerApplyStatus
	} from '@/constant/schedule.js';
	import {
		getEnableYuewanSwitch,
		getDictOpen
	} from '@/constant/login.js';
	import {
		wechatAppVersion,
		baseImageUrl
	} from '@/config/config.js';
	import {
		getAuditHomeIcon,
		getRunHomeIcon
	} from '@/constant/home.js';
	import {
		getdefaultAddress,
		submitOrder
	} from '@/constant/cart.js';
	var customer_id = uni.getStorageSync('customerId');
	export default {
		components: {
			homeHot,
			homeSell,
			homeOnlineHot
		},
		data() {
			return {
				baseImageUrl: baseImageUrl,
				indicatorDots: true,
				autoplay: true,
				interval: 3000,
				duration: 500,
				checkWetchatEnableYueWan: checkWetchatEnableYueWan,
				typeList: [{
					text: '交朋友',
					icon: require('../../static/new/icon.png'),
					path: '/pages/friend/index',
					show: false

				}, {
					text: '商城',
					icon: require('../../static/new/icon1.png'),
					path: '/pagesB/mall/index',
					show: true
				}, {
					text: '客房',
					icon: require('../../static/new/icon3.png'),
					path: '/pages/room/xyRoom/index',
					show: true,
					type: 1,
				}, {
					text: '会员中心',
					icon: require('../../static/new/icon4.png'),
					path: '/pages/mine/index',
					type: 1,
					show: true
				}],
				hotList: ['', '', '', '', '', ''],
				swoingList: [],
				productList: [],
				playerList: [],
				onlinePlayList: [],
				outlink: '',
				showjl: false
			};
		},
		onLoad() {


			// showShareMenu();
		},
		onShow() {
			this.loadHomeInfo();
			this.getEnableYuewanSwitch();
		},
		methods: {

			async loadHomeInfo() {
				// 人气
				let playRes = await queryPlayerList({})
				this.playerList = playRes.slice(0, 5);
				// 推荐
				let onlineRes = await queryPlayerList({
					isRecommend: 1
				})
				// 热卖
				this.onlinePlayList = onlineRes.slice(0, 5);
				// console.log(this.playerList, 'this.playerList')
				let productRes = await listMallProduct({})
				this.productList = productRes.slice(0, 5);
				let swoingRes = await allHomePage({
					homePageImageType: 1
				})
				this.swoingList = swoingRes;

				// let res = await getDefaultInfo();
				// this.swoingList = res.swoings;
				// this.productList = res.stores;
				// this.playerList = res.players;
				// this.onlinePlayList = res.onlinePlayers;
			},
			// async initBanner() {
			// 	this.typeList = [];
			// 	//是否需要教练
			// 	if (this.checkWetchatEnableYueWan('')) {
			// 		this.typeList = await getRunHomeIcon({});
			// 	} else {
			// 		this.typeList = await getAuditHomeIcon({});
			// 	}
			// 	//this.typeList = await getAuditHomeIcon({});
			// },
			gotoPage(item) {
				if (item.type == 1) {
					uni.switchTab({
						url: item.path
					});
				} else {
					uni.navigateTo({
						url: item.path
					});
				}
			},

			player_list() {
				uni.switchTab({
					url: '../player/index'
				});
			},
			mall_list() {
				uni.switchTab({
					url: '../../pagesB/mall/index'
				});
			},
			clickProductItem(productId) {
				uni.navigateTo({
					url: '../mall/malldetail/index?productId=' + productId
				});
			},
			clickHeaderImg(item) {
				if (!item.detailurl) {
					return;
				}
				// let url = encodeURIComponent(item.detailurl);
				// uni.navigateTo({
				// 	url: '/packagePages/index/outlink/index?url=' + url
				// });
			},
			gtesubmitOrder() {
				let params = {
					"cartIds": '2211',
					"storeId": 0,
					// "tableNumber":"DESKTOP-2KOB1IQ",
					"deliveryType": 1,
					"addressId": '',
				}

				submitOrder(params);
			},
			async getEnableYuewanSwitch() {
				getDictOpen('make_friends_on').then(res => {
					this.showjl = res.data == 1 ? true : false
					this.typeList[0].show = this.showjl
				})
				getDictOpen('mall_on').then(res => {
					let show = res.data == 1 ? true : false
					this.typeList[1].show = show
				})
				// try {
				// 	let res = await getDictOpen('make_friends_on');
				// 	this.showjl=res.data==1?true:false
				// 	// this.showjl=res.data==1?false:true
				// 	this.typeList[0].show=this.showjl
				// 		this.typeList[1].show=this.showjl
				// 	uni.setStorageSync('wetchatEnableYueWan', res.data);
				// 	// this.initBanner();
				// } catch (e) {}
			}
		}
	};
</script>
<style scoped lang="scss">
	.container {
		background-color: #f6f6f6;
		height: 100vh;
		overflow-y: auto;
		overflow-x: hidden;
	}

	.swiper {
		height: 300rpx;
	}

	.header-swiper {
		padding: 20rpx 30rpx 20rpx 30rpx;
	}

	.banner-img {
		width: 100%;
		height: 300rpx;
		border-radius: 12rpx;
	}

	.baner-top-item {
		display: flex;
		flex-direction: column;
		align-items: center;

		.type-container__item-icon-box {
			width: 120rpx;
			height: 120rpx;
			border-radius: 20rpx;
			background-color: #fff;
			// box-shadow: 0px 2px 8px rgba(0,0,0,0.05);
			display: flex;
			justify-content: center;
			align-items: center;
			// margin-bottom: 20rpx;
		}

		.type-container__item-icon {
			width: 90rpx;
			height: 90rpx;
			margin-bottom: 0 !important;

		}

		text {
			font-size: 14px;
		}
	}

	.type-container {
		margin: 20rpx 30rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		// background-color: #f6f6f6;
		// padding: 0 30rpx;
		background-color: #fff;
		// box-shadow: 0px 2px 8px rgba(0,0,0,0.05);
		border-radius: 6px;

		&__item {
			font-size: $main-text-size-28;
			color: #202020;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 20rpx;
			padding-bottom: 20rpx;

			&-icon {
				width: 106rpx;
				height: 106rpx;
				margin-bottom: 14rpx;
			}
		}
	}

	.hot-container {
		width: 100%;
		font-size: 30rpx;
		color: #333333;
		// background-color: #f6f6f6;
		display: flex;
		flex-direction: column;
		padding-bottom: 20rpx;

		&__header {
			display: flex;
			align-items: center;
			padding: 20rpx 0 20rpx 30rpx;
			font-family: 'SourceHanSansCN-Medium' !important;

			&-name {
				color: $main-text-color-gray-33;
				font-size: $main-text-size-34;
				font-weight: bold;
			}
		}

		.hot-swiper {
			height: 430rpx;
			display: flex;
			overflow-x: auto;

			&__item {
				display: inline-block;

				box-shadow: none;
			}
		}
	}

	.hot-swiper__item:first-child {
		margin-left: 30rpx;
	}

	.hot-swiper__item:last-child {
		padding-right: 10rpx;
	}

	.hot-swiper::-webkit-scrollbar {
		display: none;
	}
</style>